package com.quyunshuo.module.home.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View

class MyInstructionView(
    context: Context,
    attrs: AttributeSet? = null,
) : View(context, attrs) {

    private val instructionWidth = 37f
    private val instructionSpace = 10f
    private val instructionHeight = 37f

    private val whitePaint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val grayPaint = Paint(Paint.ANTI_ALIAS_FLAG)

    init {
        whitePaint.color = Color.WHITE
        grayPaint.color = Color.GRAY
    }
    private var select: Int = 1
        set(value) {
            field = value
            invalidate()
        }



    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)

        val mode = MeasureSpec.getMode(heightMeasureSpec)
        var size = MeasureSpec.getSize(heightMeasureSpec)

        if (mode!=MeasureSpec.EXACTLY) {
            val heightSize = (instructionHeight+paddingTop+paddingBottom).toInt()
            size = heightSize.coerceAtMost(size)
        }

        val width =  MeasureSpec.getSize(widthMeasureSpec)
        setMeasuredDimension(width,size)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val annWidth = instructionWidth-paddingStart-paddingEnd
        var fl =0f
        for (i in 0 until 3) {
            //30 +0+0+0 = 30
            //30+30 +0+5+ = 65
            //60+0 10+30 = 100
            if (i == select){
                canvas.drawCircle(annWidth+paddingStart+ (i * instructionSpace)+fl,instructionHeight/2,instructionWidth/2,whitePaint)
                fl = annWidth*(i+1)
            }else{
                canvas.drawCircle(annWidth+paddingStart+ (i * instructionSpace)+fl,instructionHeight/2,instructionWidth/2,grayPaint)
                fl = annWidth*(i+1)
            }


        }
    }

}